// Fill out your copyright notice in the Description page of Project Settings.


#include "UI/SelectLevelUI/UMG/UI_SelectLevelMain.h"
#include "Components/Button.h"
#include "Components/CanvasPanel.h"
#include "Kismet/GameplayStatics.h"
#include "UI/SelectLevelUI/UMG/UI_LevelButton.h"

void UUI_SelectLevelMain::NativeConstruct()
{
	Super::NativeConstruct();

	// 初始化选择关卡按钮
	InitSelectLevelButton();

	ReturnMenuButton->OnClicked.AddDynamic(this, &UUI_SelectLevelMain::ReturnMenu);
}

void UUI_SelectLevelMain::InitSelectLevelButton()
{
	if (SelectMap)
	{
		TArray<UPanelSlot*> PanelSlots = SelectMap->GetSlots();
		for (UPanelSlot* PanelSlot : PanelSlots)
		{
			// 判断是否为该类型的类。通过Cast转换判断也可以。
			// PanelSlot->Content->IsA(UUI_LevelButton::StaticClass);
			if (UUI_LevelButton* LevelButton = Cast<UUI_LevelButton>(PanelSlot->Content))
			{
				AllLevelButton.Add(LevelButton);
			}
		}
	}
}

void UUI_SelectLevelMain::ReturnMenu()
{
	UGameplayStatics::OpenLevel(GetWorld(), "Hall_Map");
}
